﻿using PLC;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RulesEngine.Rule
{
    public class NetStateRule : ThresholdRule
    {
        private PLCData plcData;

        private int connectFailedTimes;
        private int connectSuccessTimes;

        public int ConnectFailedTimes { get => connectFailedTimes; set => connectFailedTimes = value; }
        public int ConnectSuccessTimes { get => connectSuccessTimes; set => connectSuccessTimes = value; }



        protected override bool chargeState(State state)
        {
            //判断网络触发告警 
            if (state == State.Triggerd)
            {
                return plcData.ContinueNetConnectFailedTime >= ConnectFailedTimes;
            }
            //判断网络恢复告警
            else if (state == State.Recovered)
            {
                return plcData.ContinueNetConnectFailedTime >= connectSuccessTimes;
            }
            return false;
        }
    }
}
